{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div id="toolbar" class="row">
    <div class="col-sm-12 m-b-xs">
        <button type="button" class="btn-sm btn-success" onclick="wechat_keys.add()">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加规则
        </button>
        <button type="button" class="btn-sm btn-danger disabled">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除规则
        </button>
    </div>
</div>
<!--工具栏 end-->
{/block}
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="table" ></table>
</div>
{/block}
{block name="script"}
<script src="__STATIC__/admin/plugins/table-export/tableExport.min.js"></script>
<script src="__STATIC__/admin/plugins/bootstrap-table/extensions/export/bootstrap-table-export.min.js"></script>
<script type="text/javascript">
    $("input[class='form-control']").keypress(function (e) {
        var e = e || window.event;
        if (e.keyCode == 13) {
            $(".btn.btn-info").click();
        }
    });
    window.wechat_keys = {
        //定义工具栏
        add: function(){ //添加
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatKeys/add")}?iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        edit: function(id){ //编辑
            parent.layer.open({
                type: 2,
                title: '{$title} > 编辑',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("admin/wechatKeys/edit")}?id='+id+'&iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },

        del: function(){ //删除


        },
        //操作格式化
        opert: function(value,row){
            var rst = '';
            var edit_auth = '{:auth("$classuri/edit")}';
            var resume_auth = '{:auth("$classuri/resume")}';
            var forbid_auth = '{:auth("$classuri/forbid")}';
            var del_auth = '{:auth("admin/wechatKeys/del")}';
            if(edit_auth) {
                rst += '<a onclick="wechat_keys.edit('+row.id+')" class="btn btn-outline btn-default btn-xs">编辑</a> ';
            }
            if(forbid_auth && row.status == 1) {
                rst += '<a onclick="$.Oa.status(this,\'string\')" data-url="{:url(\'admin/wechatKeys/forbid\')}" data-id="'+row.id+'" data-value="2" class="btn btn-outline btn-warning btn-xs">禁用</a> ';
            }
            if(resume_auth && row.status == 2){
                rst += '<a onclick="$.Oa.status(this,\'string\')" data-url="{:url(\'admin/wechatKeys/resume\')}" data-id="'+row.id+'" data-value="1" class="btn btn-outline btn-primary btn-xs">启用</a> ';
            }
            if(del_auth) {
                rst += '<a onClick="$.Oa.delete(this,false,false)" data-href="{:url(\'admin/wechatKeys/del\')}" data-id="'+row.id+'" class="btn btn-outline btn-danger btn-xs">删除</a> ';
            }
            return rst;
        }
    }
    $('#table').bootstrapTable({
        toolbar: "#toolbar",
        search:true,
        showColumns: true,
        showRefresh: false,
        showExport: true,                     //是否显示导出
        exportDataType: "basic",              //basic', 'all', 'selected'.

        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"admin/wechatKeys/index\")}",
        pageNumber: 1, //初始化加载第一页，默认第一页
        pagination:true,//是否分页
        sortOrder: 'desc',
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            return {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {checkbox:true,width: 20},
            {field:'id',title:'ID',width: 20},
            {field:'keys',title:'关键字',width: 80},
            {field:'type',title:'回复类型',width: 80},
            {field:'content',title:'回复内容',width: 80},
            {field:'create_at',title:'更新时间',width: 80},
            {field:'status_str',title:'状态',align:'center',width: 80,formatter:function(value,row){
                return  row.status == 1 ? '<span class="label label-primary">使用中</span>' : '<span class="label label-danger">已禁用</span>';
            }},
            {field:'action',title:'操作',width: 80,formatter:wechat_keys.opert},
        ]
    })
</script>
{/block}